<!-- 故事投稿 -->
<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="storyContribute_content">
		<z-paging ref="paging" :refresher-end-bounce-enabled="false" :refresher-complete-duration="300" :refresher-complete-delay="500"
		:default-page-size="100"
		 v-model="dataList" 
		 @query="queryList" 
		 :fixed="false" 
		 :auto="false"
		 loading-more-no-more-text="已经到底线了">
			<view class="box" v-for="(item,index) in dataList" :key="index" @click="clickToItem(item)">
				<view class="box_info">
					<view class="box_info_title">{{ item.name }}</view>
					<view class="box_info_info">
						<view class="box_info_info_author">{{ item.author }}</view>
						<view class="box_info_info_redNum">
							<text style="color: #D98A47">{{item.num_read}}</text>
							<text style="color: #999DA2">阅读</text>
						</view>
					</view>
				</view>
				<view class="box_img">
					<image class="image" :src="item.thumbnail||item.cover" mode="aspectFill"></image>
				</view>
			</view>
		</z-paging>
	</view>
</template>

<script>
	import interfaces from "@/utils/interfaces.js"
	import config from "@/utils/config.js"
	export default {
		components: {
		},
		data() {
			return {
				dataList:[],
				firstLoaded: false
			}
		},
		props:{
			//当前组件的index，也就是当前组件是swiper中的第几个
			tabIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			//当前swiper切换到第几个index
			currentIndex: {
				type: Number,
				default: function(){
					return 0
				}
			},
			data: {
				type: Object,
				default: function(){
					return {}
				}
			}
		},
		watch: {
			currentIndex: {
				handler(newVal) {
					if(newVal === this.tabIndex){
						//懒加载，当滑动到当前的item时，才去加载
						if(!this.firstLoaded){
							setTimeout(() => {
								this.$refs.paging.reload();
							}, 100);
						}
					}
				},
				immediate: true
			},
		},
		methods: {
			queryList(pageNum, pageSize) {
				// console.log("当前" + pageNum + "-" + pageSize)
				let id = this.data.id
				let url = interfaces.square_block_rankinglist + id + ".json";
				let self = this
				self.request({
					url:url,
					methods:"GET",
					success:(res)=> {
						// console.log(res)
						self.dataList = res.content[0].lists
						self.$refs.paging.complete(self.dataList)
						self.firstLoaded = true
					},
					fail:(error)=> {
						console.log("错误 错误 错误:" + error + ":" + url)
					}
				})			
			},
			clickToItem(item) {
				let data = JSON.stringify(item)
				uni.navigateTo({
					url:'/pages/tabBar/square/storyContribute/storyContributeDetails/storyContributeDetails?data=' + data
				})
			}
		}
	}
</script>

<style lang="scss">
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.storyContribute_content {
		height: 100%;
		
		.box {
			display: flex;
			box-sizing: border-box;
			width: 100%;
			height: 220rpx;
			padding: 0px 15px;
			margin: 15px 0px;
			justify-content: space-between;
			// background-color: orange;
			
			.box_info{
				display: flex;
				box-sizing: border-box;
				flex-direction: column;
				width: 100%;
				// background-color: purple;
				.box_info_title{
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					text-overflow: ellipsis;
					font-size: 16px;
					color: #000000;
					margin-top: 10px;
					margin-right: 5px;
					
				}
				.box_info_info{
					display: flex;
					box-sizing: border-box;
					justify-content: space-between;
					align-items: center;
					margin-top: 10px;
					margin-right: 8px;
					// background-color: greenyellow;
					
					.box_info_info_author{
						font-size: 16px;
						color: #999DA2;
					}
					.box_info_info_redNum{
						font-size: 16px;
						justify-content: right;
					}
				}
			}
			
			.box_img{
				flex-shrink: 0;
				width: 250rpx;
				border-radius: 15px;
				.image{
					width: 100%;
					height: 100%;
					border-radius: 15px;
				}
			}
			
		}
		
	}
</style>